import {ref} from 'vue'
import axios from 'axios'

function load(url: string) {
    //0 not start , 1 loading, 2 loaded,3 error
    const loading = ref(0)
    const wsa = ref<ArrayBuffer>(new ArrayBuffer(0))
    const error = ref(null)

    axios.get(url, {headers: {'Access-Control-Allow-Origin': '*'}, responseType: 'arraybuffer'})
        .then(res => {
            console.error(res)
            wsa.value = res.data
            console.error(wsa)
            loading.value = 2
        }).catch(e => {
        error.value = e
        loading.value = 3
    })

    return {loading, wsa, error}
}

export default load

